using System;
using System.Collections.Generic;
using System.Text;
using Barrage.Audios;

namespace Barrage.Items
{
    /// <summary>
    /// JukeboxItem is simply an item with a Jukebox audio instance
    /// </summary>
    public class JukeboxItem:Item
    {
        private Jukebox jukeBox;
        /// <summary>
        /// The item's associated jukebox
        /// </summary>
        public Jukebox Jukebox { get { return jukeBox; } }

        /// <summary>
        /// Inits the item with an already created jukebox
        /// </summary>
        /// <param name="box">A Jukebox instance</param>
        public JukeboxItem(Jukebox box)
        {
            this.jukeBox = box;
            addAudio(box);
           
        }

        /// <summary>
        /// Inits the item loading the jukebox data from the path specified
        /// </summary>
        /// <param name="path"></param>
        public JukeboxItem(string path)
            : this(new Jukebox(path))
        {            
        }

        /// <summary>
        /// Inits the item loading the jukebox data from the default path
        /// </summary>
        public JukeboxItem()
            : this(new Jukebox())
        {
        }

        /// <summary>
        /// Starts the jukebox music
        /// </summary>
        public void Start()
        {
            jukeBox.Start();
        }

        /// <summary>
        /// Stops the jukebox music
        /// </summary>
        public void Stop()
        {
            jukeBox.Stop();
        }

        /// <summary>
        /// Gets/Sets jukebox volume
        /// </summary>
        public float Volume { get { return jukeBox.Volume; } set { jukeBox.Volume = value; } }
        /// <summary>
        /// Tells if the jukebox is playing a sound
        /// </summary>
        public bool Playing { get { return jukeBox.Playing; }  }

        /// <summary>
        /// Gets the currently played track information
        /// </summary>
        public TrackInfo CurrentTrackInfo { get { return jukeBox.CurrentTrackInfo; } }

        /// <summary>
        /// \internal Autostarts the jukebox if necessary and updates item data
        /// </summary>
        protected override void DoUpdate()
        {
            if (!jukeBox.Playing)
                jukeBox.Start();
            base.DoUpdate();
        }
    }
}
